//
//  ShowUnlockPageVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/28.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "ShowUnlockPageVC.h"
#import "DBGuestureLock.h"//添加手势
#import "myTabBarViewController.h"//tabbar
#import "DrawGesturePasswordVC.h"//绘制手势密码
#import "myTabBarViewController.h"

@interface ShowUnlockPageVC ()

@end

@implementation ShowUnlockPageVC

//- (void)viewDidLoad {
//    [super viewDidLoad];
//    self.view.backgroundColor = COLOR_EVERYVIEWBG;
//    
//    [self initWithShowUnlockPageVCSubviews];
//    
//    //忘记手势密码
//    UIButton *button_forgetGesture = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-120, kScreenHeight-50, 120, 30)];
//    [self.view addSubview:button_forgetGesture];
//    [button_forgetGesture setTitle:@"忘记手势密码?" forState:UIControlStateNormal];
//    [button_forgetGesture setTitleColor:RXDColor(59, 167, 217) forState:UIControlStateNormal];
//    [button_forgetGesture.titleLabel setFont:[UIFont systemFontOfSize:Font_SIZE_22]];
//    [button_forgetGesture addTarget:self action:@selector(forgetGesturePasswordAction) forControlEvents:UIControlEventTouchUpInside];
//    
//}
//
//- (void) viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//    self.navigationController.navigationBarHidden = YES;
//}
//
//- (void) viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//    self.navigationController.navigationBarHidden = NO;
//}

- (id) initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self initWithShowUnlockPageVCSubviews];
    }
    
    return self;
}

- (void) initWithShowUnlockPageVCSubviews
{

    UILabel * label_tips = [[UILabel alloc] initWithFrame:CGRectMake(30*PROPORTION_WIDTH, 120, kScreenWidth-30*PROPORTION_WIDTH*2,30*PROPORTION_WIDTH)];
    [self addSubview:label_tips];
    label_tips.textAlignment = NSTextAlignmentCenter;
    label_tips.textColor = COLOT_TEXTGRAY;
    label_tips.font = [UIFont systemFontOfSize:Font_SIZE_24];
    
    //Working with block:
    DBGuestureLock *lock = [DBGuestureLock lockOnView:self onPasswordSet:^(DBGuestureLock *lock, NSString *password) {
        if (lock.firstTimeSetupPassword == nil) {
            lock.firstTimeSetupPassword = password;
            NSLog(@"varify your password");
            label_tips.text = @"请再次绘制解锁图案";
        }
    } onGetCorrectPswd:^(DBGuestureLock *lock, NSString *password) {
        if (lock.firstTimeSetupPassword && ![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
            lock.firstTimeSetupPassword = DBFirstTimeSetupPassword;
            NSLog(@"password has been setup!");

        } else {
            NSLog(@"login success");
            
//            myTabBarViewController *tabBarView = [[myTabBarViewController alloc] init];
//            self.view.window.rootViewController = tabBarView;
            
        }
    } onGetIncorrectPswd:^(DBGuestureLock *lock, NSString *password) {
        if (![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
            NSLog(@"Error: password not equal to first setup!");
            label_tips.text = @"两次绘制不一样";
            //两次密码不一致则重头开始
            [DBGuestureLock clearGuestureLockPassword]; //just for test
            lock.firstTimeSetupPassword = nil;
            
        } else {
            NSLog(@"login failed");
        }
    }];
    
    [self addSubview:lock];
    
    label_tips.text = @"请设置你的手势密码";
   
    self.backgroundColor = COLOR_EVERYVIEWBG;
}

#pragma mark --- 忘记手势
- (void) forgetGesturePasswordAction
{
    
//    DrawGesturePasswordVC *drawGestureView = [[DrawGesturePasswordVC alloc] init];
//    drawGestureView.str_fromWhere = @"appHomeDone";
//    [self.navigationController pushViewController:drawGestureView animated:YES];
    
//    myTabBarViewController *tabBarView = [[myTabBarViewController alloc] init];
//    self.view.window.rootViewController = tabBarView;

}




@end
